package com.ygxsk.carhome.ui.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.flyco.roundview.RoundTextView;
import com.tencent.mmkv.MMKV;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.enumwrap.PainBookingState;
import com.ygxsk.carhome.response.PaintBookingItemBean;
import com.ygxsk.carhome.utils.CommUtils;

import java.math.BigDecimal;
import java.util.List;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-09-12  10:00
 * @Description:添加预约的历史记录的适配器；
 */
public class PaintBookingSumHistoryAdapter extends BaseQuickAdapter<PaintBookingItemBean, BaseViewHolder> {

    public PaintBookingSumHistoryAdapter(int layoutResId, @Nullable List<PaintBookingItemBean> data) {
        super(layoutResId, data);

        addChildClickViewIds(R.id.textViewPaintBookingQrCode, R.id.textViewPaintBookingCancel);

    }

    @Override
    protected void convert(@NonNull BaseViewHolder baseViewHolder, PaintBookingItemBean paintBookingItemBean) {

        if (paintBookingItemBean != null) {


            //房间号
            String siteNo = paintBookingItemBean.getSiteNo();

            //订单的状态
            String orderStateInfo = paintBookingItemBean.getOrderStateInfo();


            //orderState:1代表已支付未使用
            //订单状态的数值 格式
            String orderState = paintBookingItemBean.getOrderState();

            //预约日期 是当天的值
            String useTime = paintBookingItemBean.getUseTime();

            //当天预约的   开始时段
            String rentBeginTime = paintBookingItemBean.getRentBeginTime();

            //当天预约的   结束
            String rentEndTime = paintBookingItemBean.getRentEndTime();

            //支付方式
            String payMode = paintBookingItemBean.getPayMode();

            //支付方式的 汉字格式
            String payModeInfo = paintBookingItemBean.getPayModeInfo();

            //核销编码
            String powerCode = paintBookingItemBean.getAccessCode();

            //时段单价
            BigDecimal memberPrice = paintBookingItemBean.getMemberPrice();

            String memberPriceString = "";
            if (memberPrice != null) {
                memberPriceString = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + CommUtils.formatComma2BigDecimal(memberPrice) + StringUtils.getString(R.string.unitmoney);
            } else {
                memberPriceString = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + CommUtils.formatComma2BigDecimal(0.00) + StringUtils.getString(R.string.unitmoney);
            }

            //支付总金额
            BigDecimal totalAmount = paintBookingItemBean.getTotalAmount();
            String totalAmountString = "";
            if (totalAmount != null) {
                totalAmountString = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + CommUtils.formatComma2BigDecimal(totalAmount) + StringUtils.getString(R.string.unitmoney);
            } else {
                totalAmountString = MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + CommUtils.formatComma2BigDecimal(0.00) + StringUtils.getString(R.string.unitmoney);
            }

            //

            //findViews
            //房间号内容
            TextView textViewSiteNo = (TextView) baseViewHolder.getView(R.id.textViewSiteNo);
            //右侧的状态信息
            TextView textViewOrderStateInfo = (TextView) baseViewHolder.getView(R.id.textViewOrderStateInfo);
            //预约日期
            TextView textViewRentDay = (TextView) baseViewHolder.getView(R.id.textViewRentDay);
            //预约开始时间
            TextView textViewRentBeginTime = (TextView) baseViewHolder.getView(R.id.textViewRentBeginTime);
            //预约结尾时间
            TextView textViewRentEndTime = (TextView) baseViewHolder.getView(R.id.textViewRentEndTime);
            //付款方式 文字格式
            TextView textViewPayModeInfo = (TextView) baseViewHolder.getView(R.id.textViewPayModeInfo);
            //预约单价
            TextView textViewMemberAmount = (TextView) baseViewHolder.getView(R.id.textViewMemberAmount);
            //核销编码
            TextView textViewPowerCode = (TextView) baseViewHolder.getView(R.id.textViewPowerCode);
            //支付总金额
            TextView textViewTotalAmount = (TextView) baseViewHolder.getView(R.id.textViewTotalAmount);


            //包裹【取消支付】和【预约二维码】的外侧包裹布局；
            LinearLayout linearLayoutPaintBookingWrap = (LinearLayout) baseViewHolder.getView(R.id.linearLayoutPaintBookingWrap);
            //orderState:1代表已支付未使用
            //查看二维码的按钮，是一个单独的接口查看,只有已支付完毕的，有二维码展示能力
            RoundTextView textViewPaintBookingQrCode = (RoundTextView) baseViewHolder.getView(R.id.textViewPaintBookingQrCode);

            //取消预约
            RoundTextView textViewPaintBookingCancel = (RoundTextView) baseViewHolder.getView(R.id.textViewPaintBookingCancel);

            //orderState:1代表已支付未使用
            if (TextUtils.equals(orderState, PainBookingState.STATE_1.getValue())) {
                textViewPaintBookingQrCode.setVisibility(View.VISIBLE);
                textViewPaintBookingCancel.setVisibility(View.VISIBLE);
            } else {
                textViewPaintBookingQrCode.setVisibility(View.GONE);
                textViewPaintBookingCancel.setVisibility(View.GONE);
            }

            //直接填充值
            CommUtils.setText(textViewSiteNo, siteNo);
            CommUtils.setText(textViewOrderStateInfo, orderStateInfo);
            CommUtils.setText(textViewRentDay, CommUtils.getTimeHasNoMMddss(useTime));

            CommUtils.setText(textViewRentBeginTime, rentBeginTime);
            CommUtils.setText(textViewRentEndTime, rentEndTime);
            CommUtils.setText(textViewPayModeInfo, payModeInfo);
            //核销编码 2023-12-13 18:05:52  powerCode
            CommUtils.setText(textViewPowerCode, powerCode);
            CommUtils.setText(textViewMemberAmount, memberPriceString);
            CommUtils.setText(textViewTotalAmount, totalAmountString);

        }

    }
}
